#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

class MinStack {
public:
    /** initialize your data structure here. */
    MinStack() {
        this->minvalue = INT32_MAX;
    }
    
    void push(int x) {
        this->Vstack.push_back(x);
        this->minvalue = min(minvalue,x);
    }
    
    void pop() {
        if(this->Vstack.size()!=0){
            int popValue = *(this->Vstack.end()-1);
            Vstack.erase(this->Vstack.end()-1);
            if(popValue==minvalue){
                minvalue = INT32_MAX;
                for(int i = 0;i<this->Vstack.size();i++){
                    minvalue = min(minvalue,this->Vstack[i]);
                }
            }
        }
    }
    
    int top() {
        return *(this->Vstack.end()-1);
    }
    
    int getMin() {
        return minvalue;
    }
public:
    vector<int> Vstack;
    int minvalue;
};

int main(){
    int a,b;
    MinStack MS;
    MS.push(5);
    MS.push(2);
    MS.push(6);
    MS.push(1);
    cout<<MS.top()<<endl;
    cout<<MS.getMin()<<endl;
    MS.pop();
    cout<<MS.top()<<endl;
    cout<<MS.getMin()<<endl;
    system("pause");
    
}